package com.example.controller;

import com.example.pojo.Evaluate;
import com.example.pojo.Result;
import com.example.service.impl.EvaluateServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
@Slf4j
@CrossOrigin
@RequestMapping("/evaluate")
@RestController
public class EvaluateController {
    @Autowired
    private EvaluateServiceImpl evaluateService;

    @Autowired
    private HttpServletRequest request;

    //租客添加评论
    @PostMapping
    public Result addEvaluate(@RequestBody Evaluate evaluate){
        log.info("{}",evaluate);
        if(evaluate.getPjxj()==null){
            return Result.error("请输入评价星级");
        }
        if(evaluate.getNr()==null || evaluate.getNr()==""){
            return Result.error("请输入相关描述");
        }
        evaluateService.addEvaluate(evaluate,request);
        return Result.success();
    }

    //租客显示评论
    @GetMapping("/tenant")
    public Result getEvaluateTenant(){
        List<Evaluate> list= evaluateService.getEvaluateTenant(request);
        return Result.success(list);
    }

    //房东显示评论
    @GetMapping("/landlady")
    public Result getEvaluateLandlady(){
        List<Evaluate> list= evaluateService.getEvaluateLandlady(request);
        return Result.success(list);
    }

    //房源显示评论
    @GetMapping("/{id}")
    public Result getEvaluateId(@PathVariable Integer id){
        List<Evaluate> list=evaluateService.getEvaluateId(id);
        return Result.success(list);
    }
}
